package com.study

import android.app.Application
import com.alibaba.android.arouter.launcher.ARouter
import com.study.base.BaseApp
import com.study.base.BuildConfig
import com.study.base.config.ModuleConfig

/**
 * <pre>
 *     author : fauks
 *     time   : 2020/03/21
 *     desc   :
 * </pre>
 */
class App : BaseApp() {

    override fun onCreate() {
        super.onCreate()
        if (isDebug()) {
            ARouter.openLog()
            ARouter.openDebug()
        }
        ARouter.init(this)
        initModuleApp(this)
        initModuleData(this)
    }

    override fun initModuleApp(application: Application) {
        //调用module方法初始化
        val moduleAppNames = ModuleConfig.moduleAppNames
        for (moduleAppName in moduleAppNames) {
            val clz = Class.forName(moduleAppName)
            val baseApp: BaseApp = clz.newInstance() as BaseApp
            baseApp.initModuleApp(application)
        }
    }

    override fun initModuleData(application: Application) {
        val moduleAppNames = ModuleConfig.moduleAppNames
        for (moduleAppName in moduleAppNames) {
            val clz = Class.forName(moduleAppName)
            val baseApp: BaseApp = clz.newInstance() as BaseApp
            baseApp.initModuleData(application)
        }
    }

    fun isDebug(): Boolean {
        return BuildConfig.DEBUG
    }
}